package cn.org.tpeach.nosql.view;

import javafx.scene.AccessibleAttribute;
import javafx.scene.AccessibleRole;
import javafx.scene.control.IndexRange;
import javafx.scene.control.PasswordField;
import javafx.scene.control.Skin;
import javafx.scene.control.TextField;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import lombok.Getter;
import lombok.Setter;

/**
 * 密码可显示
 */
@Getter
@Setter
public class PasswordShowField extends PasswordField {
    /**
     * 是否显示密码
     */
    private boolean showPassword;

    private char  bullet = '\u25cf';


    /**
     * Transfers the currently selected range in the text to the clipboard,
     * removing the current selection.
     */
    @Override
    public void cut() {
        if(showPassword) {
            copy();
            IndexRange selection = getSelection();
            deleteText(selection.getStart(), selection.getEnd());
        }
    }

    /**
     * Transfers the currently selected range in the text to the clipboard,
     * leaving the current selection.
     */
    @Override
    public void copy() {
        if(showPassword) {
            final String selectedText = getSelectedText();
            if (selectedText.length() > 0) {
                final ClipboardContent content = new ClipboardContent();
                content.putString(selectedText);
                Clipboard.getSystemClipboard().setContent(content);
            }
        }
    }

    @Override protected Skin<?> createDefaultSkin() {
        return new PasswordShowTextFiledSkin(this);
    }


}
